package com.wnhz.work.yz.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.activity.ExhibitonBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2016/12/17.
 */
public class ExhibitionApplyAdapter extends BaseAdapter {
    private Context context;
    private View.OnClickListener listener;
    private List<ExhibitonBean.InfoEntity> info1 = new ArrayList<>();

    public ExhibitionApplyAdapter(List<ExhibitonBean.InfoEntity> info1, View.OnClickListener listener, Context context) {
        this.info1 = info1;
        this.listener = listener;
        this.context = context;
    }

    @Override
    public int getCount() {
        return info1.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ExhibitionApplyViewHolder viewHolder = new ExhibitionApplyViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.exhibition_apply_item, null);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tv_type = (TextView) convertView.findViewById(R.id.tv_type);
            viewHolder.tv_company = (TextView) convertView.findViewById(R.id.tv_company);
            viewHolder.tv_people = (TextView) convertView.findViewById(R.id.tv_people);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            viewHolder.tv_change = (TextView) convertView.findViewById(R.id.tv_change);
            viewHolder.tv_cancel = (TextView) convertView.findViewById(R.id.tv_cancel);
            viewHolder.look = (TextView) convertView.findViewById(R.id.look);
            viewHolder.rl_button = (RelativeLayout) convertView.findViewById(R.id.rl_button);//按钮布局
            viewHolder.rl_button2 = (RelativeLayout) convertView.findViewById(R.id.rl_button2);//按钮布局
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ExhibitionApplyViewHolder) convertView.getTag();
        }
        viewHolder.tv_name.setText("" + info1.get(position).getProject_name());
        String sta = "";
        if ("0".equals(info1.get(position).getStatus())) {
            sta = "未审核";
            viewHolder.rl_button.setVisibility(View.VISIBLE);
            viewHolder.rl_button2.setVisibility(View.GONE);
        } else if ("1".equals(info1.get(position).getStatus())) {
            viewHolder.rl_button.setVisibility(View.GONE);
            viewHolder.tv_type.setTextColor(context.getResources().getColor(R.color.main_color));
            sta = "审核通过";
            viewHolder.rl_button2.setVisibility(View.VISIBLE);
        } else if ("2".equals(info1.get(position).getStatus())) {
            sta = "审核不通过";
            viewHolder.tv_type.setTextColor(context.getResources().getColor(R.color.red));
            viewHolder.rl_button.setVisibility(View.GONE);
            viewHolder.rl_button2.setVisibility(View.VISIBLE);
        } else {
        }

        viewHolder.tv_type.setText("" + sta);
        viewHolder.tv_company.setText("来访公司：" + info1.get(position).getVisit_company());
        viewHolder.tv_people.setText("来访人数：" + info1.get(position).getCustom_num() + "人");

        viewHolder.tv_time.setText("申请时间：" + info1.get(position).getRequest_time());

        viewHolder.tv_change.setOnClickListener(listener);
        viewHolder.tv_change.setTag(position);
        viewHolder.tv_cancel.setOnClickListener(listener);
        viewHolder.tv_cancel.setTag(position);
        viewHolder.look.setOnClickListener(listener);
        viewHolder.look.setTag(position);

        return convertView;
    }

    class ExhibitionApplyViewHolder {
        TextView tv_name;
        TextView tv_type;
        TextView tv_company;
        TextView tv_people;
        TextView tv_time;
        TextView tv_change;
        TextView tv_cancel, look;
        RelativeLayout rl_button, rl_button2;
    }
}
